<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type">

<meta charset="utf-8">

<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">

<meta content="yes" name="apple-mobile-web-app-capable">

<meta content="black" name="apple-mobile-web-app-status-bar-style">

<meta content="telephone=no" name="format-detection">

<title>登录</title>

<link href="style/login.css" rel="stylesheet" type="text/css" />

<link href="css/vant.css" rel="stylesheet" type="text/css" />

<script src="js/jquery-3.3.1.min.js"></script>

<script src="js/vue/vue.js"></script>

<script src="js/vue/axios.js"></script>

<script src="js/vue/qs.js"></script>

<script src="js/vue/MD5.js"></script>

<script src="js/vue/vant.js"></script>

<script type="text/javascript" src="js/js.js"></script>

</head>

<body>

<div id="app">

    <div class="ve_title">{{titles}}</div>

    <div class="main">

        <div class="login_txt">登录</div>

        <div class="login_type_o">

            <span style="background-image:url(images/phone.png); color:#0092fd" id="ck_phone" onclick="check_login('phone')">短信登录</span>

            <span style="background-image:url(images/user.png)" id="ck_user"  onclick="check_login('user')">密码登录</span>

        </div>

        <input ref="login_type" id="login_type" type="hidden" value="phone" />

        <input ref="send" id="send" type="hidden" value="60" />

        <div class="login_o" id="phone_login">

            <div class="login_text">手机号</div>

            <div class="login_input">

                <input v-model="from1.phone" style="font-size: 14px;" id="phone" type="text" class="phone_input" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="11" onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入手机号码"/>

            </div>

            <div class="login_text" style="margin-top:10px">短信验证码</div>

                <div class="login_input_code"  style="padding-bottom:3px;">

                <input v-model="from1.sms_code" style="font-size: 14px;width: 50%;" id="code" type="text" class="code_input" placeholder="请输入验证码" onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="6" onafterpaste="this.value=this.value.replace(/\D/g,'')" style="width:55%;"/>

                <div class="code_getcode" @click="get_sms_code()" style="float:right;">获取验证码</div>

            </div>

        </div>

        <div class="login_o" id="user_login" style="display:none">

            <div class="login_text">手机号</div>

            <div class="login_input">

                <input v-model="from.username"

                style="font-size: 14px;" id="uphone" type="text"

                class="phone_input"   placeholder="请输入手机号"/>

            </div>

            <div class="login_text" style="margin-top:10px">密码</div>

            <div class="login_input_code"  style="padding-bottom:3px;">

                <input v-model="from.password" style="font-size: 14px;" id="upassword" type="password" class="code_input" placeholder="请输入验密码"/>

            </div> 

                <a href="#" @click="setParr" class="login_text" style="margin-top:10px; font-size:13px; text-align:right;"> 设置密码</a>

        </div>

        <div class="login_but_o" @click="gologins()">登录</div>

        <!-- <div class="wxlogin"><img src="images/wx2.png" @click="wxlogin" /></div> -->

    </div>

</div>

</body>

<script>

var app = new Vue({

    el: '#app',

    data: {

        sending:false,
        vid:'',

        titles:'',
        sendData:{},
        helloData: {},

        from:{

            phone: '',

            password: '',

            vid:'',

        },

        from1:{

            sms_code: "",

            phone: "",

            vid:''

        },

        wxinfo:''

    },

    created(){

        this.setCanS()

    },

    methods: {

        setCanS(){

            //获取登录状态

            let timeLoc=new Date()
            let besss = localStorage.getItem('memberTime');
            
            let isBeOverdue = Date.parse(besss);

            console.log(isBeOverdue)

            let Request = new Object()
            
            Request = GetRequest()

            this.vid = Request['vid']

            if(this.vid == undefined || this.vid==''|| this.vid == null){

                this.vid= ''
                return;
            }else{

                sessionStorage.setItem('vid',this.vid)

            }

            //是否微信登录

            this.wxinfo = Request['wxinfo']

            this.vid = sessionStorage.getItem('vid')

            this.from.vid=this.vid
            

            this.from1.vid=this.vid

            const params={

                vid:this.vid

            }

            sessionStorage.setItem('logo','1')

            axios.get('/mobileapi/member/login.php?act=login',{params:params}).then(data => {

                console.log(data.data)

                let { msg, code} = data.data

                    if (code != 200) {

                        window.vant.Toast.fail(msg)

                    } else {

                        var datas = data.data.data.Vname

                        this.titles=datas

                        console.log(this.titles)

                    }

                }).catch(function (error) { 

                    console.log(error); 

            });

            if(this.wxinfo!=''&&this.wxinfo!=null&&this.wxinfo!=undefined){

                this.getWxlogin()

            }

            //判断是否保存登录状态

            if(this.vid == ''){

                if(isBeOverdue!='null'&&isBeOverdue!='undefined'&&isBeOverdue!=''){

                    if(timeLoc.getTime()-isBeOverdue>0){

                        //过期

                           

                        }else{

                            //未过期

							

                            let vid=localStorage.getItem('membervid')

                            let Gtoken=localStorage.getItem('memberGtoken')

                            sessionStorage.setItem('logo','0')

                            sessionStorage.setItem('token',Gtoken)

                            sessionStorage.setItem('vid',vid)

                            let type="logo"

                            sessionStorage.setItem('type',type)

                            window.location.href='index.html?vid='+vid+'&type='+type+''

                        }

                }

            }else{

				

                if(isBeOverdue!='null'&&isBeOverdue!='undefined'&&isBeOverdue!=''){

                    //判断vid是否想同

                    let vid=localStorage.getItem('membervid')

                    if(this.vid != vid){

                       

                    }else{

                         //判断是否过期

						 

                        if(timeLoc.getTime()-isBeOverdue>0){

                          //过期

                             

                        }else{

							

                            //未过期

                            let vid=localStorage.getItem('membervid')

                            let Gtoken=localStorage.getItem('memberGtoken')

                            sessionStorage.setItem('logo','0')

                            sessionStorage.setItem('token',Gtoken)

                            sessionStorage.setItem('vid',vid)

                            let type="logo"

                            sessionStorage.setItem('type',type)

                            window.location.href='index.html?vid='+vid+'&type='+type+''

                        }

                    }

                }

            }

        },

            // //设置参数

            // setCanS(){

            //     let Request = new Object()

            //     Request = GetRequest()

            //     this.vid = Request['vid']

            //     this.wxinfo = Request['wxinfo']

            //     //获取场馆名称

            //     if(this.vid==undefined||this.vid==''||this.vid==null){

            //         this.vid=''

            //     }

            //     if(sessionStorage.getItem('vid')!=null&&sessionStorage.getItem('vid')!=''&&sessionStorage.getItem('vid')!=undefined){

            //         this.vid=sessionStorage.getItem('vid')

            //     }else{

            //         sessionStorage.setItem('vid',this.vid)

            //     }

            //     this.from.vid=this.vid

            //     this.from1.vid=this.vid

            //     const params={

            //         vid:this.vid

            //     }

            //     sessionStorage.setItem('logo','1')

            //     axios.get('/mobileapi/member/login.php?act=login',{params:params}).then(data => {

            //         console.log(data.data)

            //         let { msg, code} = data.data

            //             if (code !== 200) {

            //                 window.vant.Toast.fail(msg)

            //             } else {

            //                 var datas = data.data.data.Vname

            //                 this.titles=datas

            //                 console.log(this.titles)

            //             }

                        

            //         }).catch(function (error) { 

            //             console.log(error); 

            //     });

            //     if(this.wxinfo!=''&&this.wxinfo!=null&&this.wxinfo!=undefined){

            //         this.getWxlogin()

            //     }

            // },

            //登录

            gologins() {

                sessionStorage.setItem('logo','1')

                if(this.$refs.login_type.value=='user'){

                    var obj = this;

                    let password=md5(this.from.password)

                    password=md5(password)

                    console.log(password)

                    let from = { phone: this.from.username, password: password,vid:this.vid};

                    from =JSON.stringify(from)

                    let sign=md5(from)

                    let params={

                        from:from,

                        sign:sign

                    }

                    axios.post('/mobileapi/member/login.php?act=login_go',

                    Qs.stringify(params)).then(function(response){

                        let { msg, code} = response.data

                            if (code !== 200) {

                                window.vant.Toast.fail(msg)

                            } else {

                                var data = response.data

                                console.log(data)

                                if(data.data.login_type=='2'){

                                    sessionStorage.setItem('logo','1')

                                    sessionStorage.setItem('token',data.data.Gtoken)

                                    let venueset_list=JSON.stringify(data.data.venueset_list)

                                    sessionStorage.setItem("venueset_list",venueset_list)

                                    //跳转到选择场馆页面

                                    window.location.href='selectShop.html?vid='+this.vid+''

                                }else{

                                    sessionStorage.setItem('logo','0')

                                    sessionStorage.setItem('token',data.data.Gtoken)

                                    this.vid=data.data.Vid

                                    sessionStorage.setItem('vid',data.data.Vid)

                                    let type="logo"

                                    //保存登录有效期

									 //设置为1代表以及登录 0代表为登录

									localStorage.setItem('member',"1")

									localStorage.setItem('membervid',data.data.Vid)

									localStorage.setItem('memberGtoken',data.data.Gtoken)

									localStorage.setItem('memberType',type)

                                    let timeLoc=new Date()

                                    localStorage.setItem('memberTime',new Date(timeLoc.getTime() + 365*24*60*60*1000))

                                    sessionStorage.setItem('type',type)

                                    window.location.href='index.html?vid='+this.vid+'&type='+type+''

                                }

                            }

                        }).catch(function (error) { 

                            console.log(error); 

                    });

                }else{

                    var obj = this

                    let from = this.from1
                    from["data"] = this.sendData;
                    from =JSON.stringify(from)

                    let sign=md5(from)

                    let params={

                        from:from,

                        sign:sign

                    }

                    axios.post('/mobileapi/member/login.php?act=sms_login',

                    Qs.stringify(params)).then(data => {

                            console.log(data.data)

                            let { msg, code} = data.data

                            if (code !==200) {

                                window.vant.Toast.fail(msg)

                            } else {

                                 data = data.data

                                if(data.data.login_type=='2'){

                                    sessionStorage.setItem('logo','1')

                                    sessionStorage.setItem('token',data.data.Gtoken)

                                    let venueset_list=JSON.stringify(data.data.venueset_list)

                                    sessionStorage.setItem("venueset_list",venueset_list)

                                    //跳转到选择场馆页面

                                    window.location.href='selectShop.html?vid='+this.vid+''

                                }else{

                                    sessionStorage.setItem('logo','0')

                                    sessionStorage.setItem('token',data.data.Gtoken)

                                    this.vid=data.data.Vid

                                    sessionStorage.setItem('vid', this.vid)

                                    //保存登录有效期

									let type="logo"

									 //设置为1代表以及登录 0代表为登录

									localStorage.setItem('member',"1")

									localStorage.setItem('membervid',data.data.Vid)

									localStorage.setItem('memberGtoken',data.data.Gtoken)

									localStorage.setItem('memberType',type)

                                    let timeLoc=new Date()

                                    localStorage.setItem('memberTime',new Date(timeLoc.getTime() + 365*24*60*60*1000))

                                    sessionStorage.setItem('type',type)

                                    window.location.href='index.html?vid='+this.vid+'&type='+type+''

                                }

                            }

                            

                        }).catch(function (error) { 

                            console.log(error); 

                      })

                }

            },

            //获取手机验证码

            get_sms_code(){

                var send=parseInt(this.$refs.send.value);

                if(!isPoneAvailable(this.from1.phone)){

                    window.vant.Toast.fail("请输入正确的手机号")

                    return false;

                }

                const params={

                    phone:this.from1.phone

                }
                if (this.sending) {
                    return;
                }

                if(send==60){
                    this.sending = true;
                    var that = this;
                    axios.post('/mobileapi/member/login.php?act=getsms',Qs.stringify(params)).then(function(response){

							if(response.data.code=="200"){

								window.vant.Toast.success("短信已发，请注意查收")
                                that.sendData = response.data.data;
							}else{
                                that.sending = false;
								window.vant.Toast.fail(response.data.msg)

								

							}

                        }).catch(function (error) {

                            console.log(error,"123")

                            window.vant.Toast.fail("短信发送失败！请确认手机号是否正确。");

                    })   

                    var set=setInterval(function(){

                        var send_t=--send;

                        $(".code_getcode").html(""+send_t+"秒");

                        $("#send").val(--send_t)

                    }, 1000);

                    setTimeout(function(){

                        $(".code_getcode").html("重新获取");
                        that.sending = false;
                        $("#send").val(60)

                        clearInterval(set);

                    }, 60000);

                }	

            },

            //验证手机号正不争取

            isPoneAvailable($poneInput) {

                var myreg=/^[1][3,4,5,6,7,8,9][0-9]{9}$/;

                if (!myreg.test($poneInput)) {

                    return false;

                } else {

                    return true;

                }

            },

            setParr(){

                window.location.href='login_set.html?vid='+this.vid+''

            },

            //微信登录

            wxlogin(){

window.location.href='http://wx.bj.guanjialc.com/api/wxlogin.php?Assystem=3fc62b5aec87be2e4dd05a531412cc4f&Venid='+this.vid+'&backurl=http%3a%2f%2ffitness.guanjialc.com%2fphone%2fmember%2flogin.html%3fvid='+this.vid+''

            },

            //获取code然后跳去接口登录

            getWxlogin(){

                let params={

                    vid:sessionStorage.getItem('vid'),

                    wxinfo:this.wxinfo

                }

                axios.get('/mobileapi/member/login_wx_b.php?act=login',

                {params:params}).then(function(response){

                    let { msg, code} = response.data

                        if (code != 200) {

                            window.vant.Toast.fail(msg)

                        } else {

                            var data = response.data

                            if(data.data.login_type=='2'){

                                sessionStorage.setItem('logo','1')

                                sessionStorage.setItem('token',data.data.Gtoken)

                                let venueset_list=JSON.stringify(data.data.venueset_list)

                                sessionStorage.setItem("venueset_list",venueset_list)

                                //跳转到选择场馆页面

                                window.location.href='selectShop.html?vid='+this.vid+''

                            }else{

                                sessionStorage.setItem('logo','0')

                                sessionStorage.setItem('token',data.data.Gtoken)

                                this.vid=data.data.Vid

                                sessionStorage.setItem('vid',data.data.Vid)

                                let type="logo"

                                sessionStorage.setItem('type',type)

								localStorage.setItem('member',"1")

								localStorage.setItem('membervid',data.data.Vid)

								localStorage.setItem('memberGtoken',data.data.Gtoken)

								localStorage.setItem('memberType',type)

                                //保存登录有效期

                                let timeLoc=new Date()

                                localStorage.setItem('memberTime',new Date(timeLoc.getTime() + 365*24*60*60*1000))

                                window.location.href='index.html?vid='+this.vid+'&type='+type+''

                            }

                        }

                    }).catch(function (error) { 

                        console.log(error); 

                });

            }

        }  

})

</script>

</html>